Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add POST account functionality #15

Merged
merged 4 commits into from
May 28, 2024
Merged

Conversation

turb0c0w
Copy link
Contributor

Issue:
bcgov/entity#21267
bcgov/entity#21257
bcgov/entity#21258

Description of changes:

  • new functionality for saving record on POST /account
  • new GET /registrations endpoint

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the namex license (Apache 2.0).

jsonify([Registration.from_db(registration).model_dump(mode="json") for registration in registrations]),
HTTPStatus.OK,
)
except AuthException as auth_exception:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only kind of exception expected here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


primary_contact = user
db.session.add(primary_contact)
db.session.commit()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think multiple commits should not happen in one request. This should be in a transaction. Either everything is saved or nothing is saved.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, this should have been .flush()

"""Service to save and load regristration details from the database."""

@classmethod
def save_registration(cls, jwt_oidc_token_info, sbc_account_id, registration_request: requests.Registration):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this called after payment ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

payment will be added in a future sprint.

new_user_account = AuthService.create_user_account(token, name, mailing_address)
return jsonify(new_user_account), HTTPStatus.CREATED
registration_request = RegistrationRequest(**json_input)
selected_account = registration_request.selectedAccount
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to move the validation logic to a validator class and return all the validation errors in the request as a list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to RegistrationRequestValidator.py

)
)

registration = RegistrationService.save_registration(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is registration getting saved in the account resource?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the endpoint is both (potentially) creating SBC user accounts and also saving registrations.

Based on your feedback I have moved it to POST /registrations and I believe in a future sprint we will likely split out the SBC account portion into its own endpoint.

except AuthException as auth_exception:
return exception_response(auth_exception)
except ExternalServiceException as service_exception:
return exception_response(service_exception)


def validate_and_format_canadian_postal_code(country: str, province: str, postal_code: str):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this to a validator class

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to RegistrationRequestValidator.py

),
dateOfBirth=source.rental_property.property_manager.primary_contact_user.date_of_birth,
details=ContactDetails(
preferredName=source.rental_property.property_manager.primary_contact_user.preferredname,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see primary and secondary contact as optional. Is primary_contact_user and secondary contact_user always present? If not, primary_contact_user.firstname will throw exception

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primary Contact is enforced as mandatory in the json schema. Updated the model to reflect that its required.

db.session.refresh(primary_contact)

if registration_request.secondaryContact:
secondary_contact = models.User(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a provision to modify this data? Example , If a save functionality is supported, when the application is resumed and when the secondary contact is changed, this will create new user every time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no edit support currently, that work might come in a later sprint. Currently this method is the only time the data is saved, so there would be no orphaned records. That may change in future work.

@turb0c0w turb0c0w merged commit 903ea19 into bcgov:main May 28, 2024
5 checks passed
pwei1018 pushed a commit to pwei1018/STRR that referenced this pull request Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants